#include "FPCH.h"

#include "FFace.h"

#include "FFaceHandle.h"
#include "FMetrics.h"

namespace Font
{

	Face::Face(Library* a_Library, Family* a_Parent)
	{
		m_Library = a_Library;
		m_Family = a_Parent;

		m_Loader = NULL;
		m_Metrics = NULL;
	}

	Face::~Face()
	{
		for (std::vector<FaceHandle*>::iterator it = m_Handles.begin(); it != m_Handles.end(); )
		{
			delete *it;
			it = m_Handles.erase(it);
		}
	}

	void Face::SetMetrics(Metrics* a_Metrics)
	{
		m_Metrics = a_Metrics;
	}

	Metrics* Face::GetMetrics()
	{
		return m_Metrics;
	}

	void Face::SetLoader(Loader* a_Loader)
	{
		m_Loader = a_Loader;
	}
	
	Loader* Face::GetLoader()
	{
		return m_Loader;
	}

	FaceHandle* Face::GetHandle(unsigned int a_Size, unsigned int a_Options /*= 0*/, CharMap* a_Map /*= NULL*/)
	{
		std::map<unsigned int, FaceHandle*>::iterator found = m_HandlesBySize.find(a_Size);
		if (found != m_HandlesBySize.end())
		{
			return found->second;
		}

		FaceHandle* result = m_Metrics->CreateFace(a_Size, a_Options, a_Map);
		m_Handles.push_back(result);
		m_HandlesBySize.insert(std::pair<unsigned int, FaceHandle*>(a_Size, result));
		return result;
	}

	CharMap* Face::GetCharMap()
	{
		return m_CharMap;
	}


}; // namespace Rpt